package com.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;

import com.entity.Pets;

@Repository
public class petDaoImpl {
	@Resource
	private SessionFactory sessionFactory;
	
	//宠物查询
	public List<Pets> findAllPet(){
		String hql="from Pets";
	    Query query=this.sessionFactory.getCurrentSession().createQuery(hql);
		List<Pets> list=query.list();
	    return list;
	    
	}
	//id查询宠物
	public Pets findPetsById(int id){
		String hql="from Pets where id=?";
		Query query=this.sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter(0, id);
		Pets pets=(Pets)query.uniqueResult();
		return pets;
	}
	//修改宠物信息
	public void updatePet(Pets p){
		this.sessionFactory.getCurrentSession().update(p);
	}
}
